package com.atguigu.tingshu.search.api;

import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.model.album.AlbumInfo;
import com.atguigu.tingshu.query.search.AlbumIndexQuery;
import com.atguigu.tingshu.search.service.SearchService;
import com.atguigu.tingshu.vo.search.AlbumInfoIndexVo;
import com.atguigu.tingshu.vo.search.AlbumSearchResponseVo;
import com.atguigu.tingshu.vo.search.HomePageVo;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "搜索专辑管理")
@RestController
@RequestMapping("api/search/albumInfo")
@SuppressWarnings({"unchecked", "rawtypes"})
public class SearchApiController {

    @Resource
    private SearchService searchService;
    @GetMapping("channel/{category3Id}")
    public Result<List<HomePageVo>> channel(@PathVariable Long category3Id){
        List<HomePageVo> homePageVoList =searchService.channel(category3Id);
        return Result.ok(homePageVoList);
    }
    @PostMapping
    public Result<AlbumSearchResponseVo> search(@RequestBody AlbumIndexQuery albumIndexQuery){
        AlbumSearchResponseVo albumSearchResponseVo =searchService.search(albumIndexQuery);
        return Result.ok(albumSearchResponseVo);
    }
    @GetMapping("findRankingList/{category1Id}/{field}")
    public Result<List<AlbumInfoIndexVo>> findRankingList(@PathVariable Long category1Id,
                                                          @PathVariable String field){
        List<AlbumInfoIndexVo> albumInfoIndexVoList =searchService.findRankingList(category1Id,field);
        return Result.ok(albumInfoIndexVoList);
    }

    @GetMapping("completeSuggest/{prefix}")
    public Result<List<String>> completeSuggest(@PathVariable String prefix){
        List<String> suggestList =searchService.completeSuggest(prefix);
        return Result.ok(suggestList);
    }
}

